package com.laborer.PTSS.web.servlet;

import com.laborer.PTSS.domain.Transaction;
import com.laborer.PTSS.service.PayService;
import com.laborer.PTSS.service.impl.PayServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/pay/*")
public class PayServlet extends BaseServlet {
    private PayService payService = new PayServiceImpl();

    public void addPayment(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, IOException {
        String b_uname = request.getParameter("b_uname");
        String s_uname = request.getParameter("s_uname");
        int cid = Integer.parseInt(request.getParameter("cid"));
        int hours = Integer.parseInt(request.getParameter("hours"));
        System.out.println(request.getParameter("total"));
        float total = Float.parseFloat(request.getParameter("total"));
        System.out.println(b_uname);
        payService.addTransaction(b_uname, s_uname, cid, hours, total);
        writeValue("123", response);
    }

    public void getTransactionsList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String s_uname = request.getParameter("sellerUsername");
        List<Transaction> transactionList = payService.getTransaction(s_uname);
        System.out.println(transactionList.size());
        writeValue(transactionList, response);
    }
}
